<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../Workerman/Autoloader.php';
require_once __DIR__.'/../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/..');

$mode = $_GET['mode'];
$result = 'normal';

if ($mode == 'login'){
    $name = $_GET ['name'];

    $password = $_GET ['password'];

    $record = \Data\Tree_admin_user_DAO::getRecordByName($name);
    $user_id = $record->getID();
    if ($record != null) {
        if (md5($password) == $record->getPassword()){
            $pages = explode( ",", $record->getPage() );
            $page_str ="";
            $gruopList = \Data\Tree_mng_group_mst_DAO::getListByOrder();
            foreach ($gruopList as $group){
                $flag = false;
                foreach ($pages as $pageid){
                    $pageRecord = \Data\Tree_mng_page_mst_DAO::getRecord($pageid);
                    if ($pageRecord->getGROUP_ID() == $group->getGROUP_ID()){
                        $flag = true;
                        $page_str .= $pageRecord->getPAGE_ID()."#".$pageRecord->getPAGE_NAME()."#".$pageRecord->getURL()."@";
                    }
                }
                if ($flag){
                    $page_str = rtrim(trim($page_str),"@");
                    $page_str .= "^".$group->getGROUP_ID()."#".$group->getGROUP_NAME()."#".$group->getIMG().",";
                }
            }

            $page_str = rtrim(trim($page_str),",");

            $session = new \Utils\Util_session(false,$user_id,$name,$page_str);

            $result = 'succLogin';
        }else{
            $result = 'errLogin';
        }
    } else {
        $result = 'errLogin';
    }

}

?>
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/style.css" type="text/css" rel="stylesheet" rev="stylesheet"/>
    <title>花木问价管理后台</title>
    <script type="text/javascript">
        function doLogin() {
            var fm = document.fm;
            if (fm.name.value == "") {
                alert('请输入用户名');
                fm.name.focus();
                return false;
            }
            if (fm.password.value == "") {
                alert('请输入密码');
                fm.password.focus();
                return false;
            }
            url = "./index.php?name="+fm.name.value+"&password="+fm.password.value+"&mode=login";
            window.location.href = url;

        }
        function init() {
            var fm = document.fm;
            var msg = "<?php echo $result ?>";
            if (msg == 'succLogin') {
                fm.action = './view/pages/';
                fm.submit();
            }else if(msg == 'errLogin'){
                alert('帐号或密码错误');
            }
        }
    </script>

</head>
<body class="denglu02" onload="init()">
<form  id="fm" name="fm" method="POST" action="">
    <div class="dl">
        <div class="biaoti" style="font-size: 25px; color: #00a2d4;letter-spacing:2px"><br>花木问价管理后台<br><br><br></div>
        <div class="log">
            <ul class="xuzhi02">
                <li class="xz">使用说明</li>
                <li>1.该系统为花木问价管理后台</li>
                <li>2.操作人员需经培训才可使用本系统</li>
                <li>3.技术支持请联系1500000000</li>
            </ul>
            <ul class="deng02">

                <li style=" width:100%; height:60px;">
                    <p style="float:left;font-size:18px; color:#666;line-height:30px; ">用户名:</p>
                    <input id="name" class="i-text" type="text" errormsg="用户名至少6个字符,最多18个字符！" datatype="s6-18" ajaxurl="demo/valid.jsp" maxlength="100">
                </li>
                <div style="clear:both;"></div>

                <li style=" width:100%; height:60px;">
                    <p style="float:left;font-size:18px; color:#666;line-height:30px; ">密&#12288;码:</p>
                    <input id="password" class="i-text" type="password" errormsg="用户名至少6个字符,最多18个字符！" datatype="s6-18" ajaxurl="demo/valid.jsp" maxlength="100" >
                </li>
                <div style="clear:both;"></div>

                <li style=" width:100%; height:60px;">
                    <button id="logonbtn" class="btn-login02" onclick="doLogin();return false;" type="button" >
                        <span>登&nbsp;&nbsp;&nbsp;&nbsp;录</span>
                    </button>
                </li>
            </ul>

        </div>
    </div>
</form>
</body>
</html>
